package org.example.volunteerend.mapper;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.example.volunteerend.entity.PointsRecord;

@Mapper
public interface PointsRecordMapper {
    List<PointsRecord> findByUserId(@Param("userId") Integer userId);
    int countByUserId(@Param("userId") Integer userId);
    
    /**
     * 添加积分记录
     */
    @Insert("INSERT INTO points_records (user_id, points, reason, create_time) " +
            "VALUES (#{record.userId}, #{record.points}, #{record.reason}, NOW())")
    @Options(useGeneratedKeys = true, keyProperty = "record.recordId")
    void insert(@Param("record") PointsRecord record);
    
    /**
     * 获取积分排行榜
     */
    List<Map<String, Object>> findPointsRanking(@Param("limit") Integer limit);
} 